package com.manli.api.service;

import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.SQLReady;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.List;
import com.manli.api.pojo.Result;
import com.manli.api.util.ResultUtil;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.manli.api.pojo.QueryParams;
import com.manli.api.dao.OrderInfoDao;
import com.manli.api.dto.OrderInfo;


@Service("orderInfoService")
public class OrderInfoService {
    @Autowired
    OrderInfoDao orderInfoDao;
    @Autowired
    SQLManager sqlManager;

    
    public Result queryPage(QueryParams params) {
        /**
        * sql中表名需要修改
        */
        StringBuffer sql = new StringBuffer("select * from order_info where 1=1 ");

        SQLReady sqlReady = new SQLReady(sql.toString());

        PageQuery<OrderInfo> pageQuery = new PageQuery<OrderInfo>(params.getPage(),params.getLimit());
        PageQuery<OrderInfo> query =sqlManager.execute(sqlReady,OrderInfo.class,pageQuery);
        return ResultUtil.success(query.getList(),query.getTotalRow());
    }

    
    public Result queryAll() {
        List<OrderInfo> list = orderInfoDao.all();
        return ResultUtil.success(list);
    }

    
    public Result getById(Integer orderInfoId) {
        OrderInfo orderInfo = orderInfoDao.single(orderInfoId);
        return ResultUtil.success(orderInfo);
    }

    @Transactional
    public Result save(OrderInfo orderInfo) {
        orderInfoDao.insert(orderInfo);
        return ResultUtil.success();
    }

    @Transactional
    public Result updateById(OrderInfo orderInfo) {
        orderInfoDao.updateTemplateById(orderInfo);
        return ResultUtil.success();
    }

    @Transactional
	public Result updateTemplateById(OrderInfo orderInfo) {
        orderInfoDao.updateTemplateById(orderInfo);
        return ResultUtil.success();
    }

    @Transactional
    public Result removeByIds(List<Integer> ids) {
        for (Integer id:ids) {
            orderInfoDao.deleteById(id);
        }
        return ResultUtil.success();
    }



}
